package org.bwf.study.servcie.impl;

import org.bwf.obj.dto.WatchTimesQueryModelDTO;
import org.bwf.study.aop.RedisAnnotation;
import org.bwf.study.mapper.CinemaMapper;
import org.bwf.study.mapper.FilmMapper;
import org.bwf.study.mapper.WatchTimesMapper;
import org.bwf.study.model.Cinema;
import org.bwf.study.model.Film;
import org.bwf.study.model.WatchTimes;
import org.bwf.study.model.WatchTimesSite;
import org.bwf.study.servcie.WatchTimesService;
import org.bwf.study.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class WatchTimesServiceImpl implements WatchTimesService {

    @Autowired
    private CinemaMapper cinemaMapper;
    @Autowired
    private FilmMapper filmMapper;
    @Autowired
    private WatchTimesMapper watchTimesMapper;


    @Override
    @RedisAnnotation(Duration = 1000)
    public WatchTimesQueryModelDTO WatchTimesQueryModel(String wtId) {
        WatchTimesQueryModelDTO watchTimesQueryModelDTO = new WatchTimesQueryModelDTO();

        WatchTimes watchTimes = watchTimesMapper.selectById(wtId);
        // 转换场次信息中的座位列表
        watchTimesQueryModelDTO.setWatchTimesSites(JsonUtil.decodeJsonToList(watchTimes.getWtCostSites(), WatchTimesSite.class));

        Cinema cinema = cinemaMapper.selectById(watchTimes.getCmaId());

        Film film = filmMapper.selectById(watchTimes.getFilmId());

        watchTimesQueryModelDTO.setCinema(cinema);
        watchTimesQueryModelDTO.setFilm(film);
        watchTimesQueryModelDTO.setWatchTimes(watchTimes);

        return watchTimesQueryModelDTO;
    }
}
